package com.example.peibei.ui.fragment;

import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.dingtao.common.core.WDFragment;
import com.dingtao.common.util.SPUtils;
import com.example.peibei.R;
import com.example.peibei.base.SpConstant;
import com.example.peibei.ui.adapter.MyPagerAdapter;
import com.example.peibei.ui.weight.MySlidingTabLayout;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

import butterknife.BindView;

public class GuangChangFragment extends WDFragment {
    @BindView(R.id.slideTablaout)
    MySlidingTabLayout slideTablaout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.iv_send_order)
    ImageView iv_send_order;

    private ArrayList<Fragment> fragments = new ArrayList<>();
    private String[] mTitles = {"派单区"
            ,"动态"
//            , "圈子"
    };

    @Override
    public String getPageName() {
        return "广场Fragment";
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_square;
    }

    @Override
    protected void initView() {
        iv_send_order.setVisibility(View.GONE);
        fragments.add(new PaiDanFragment());
        fragments.add(new DynamicListFragment("1"));
//        fragments.add(new QuanZiFragment());
//        fragments.add(new SquareFragment());
        MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager(), fragments, mTitles);
        viewpager.setAdapter(adapter);
        viewpager.setOffscreenPageLimit(2);
        slideTablaout.setViewPager(viewpager);
        Drawable drawable = getContext().getDrawable(R.drawable.underline_color);
        slideTablaout.setDrawable(drawable);
        viewpager.setCurrentItem(0);

        TextView title = slideTablaout.getTitleView(0);
        title.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        TextView title1 = slideTablaout.getTitleView(0);
//        TextView title2 = slideTablaout.getTitleView(1);
        title1.setTextSize(TypedValue.COMPLEX_UNIT_SP,20);
//        title2.setTextSize(TypedValue.COMPLEX_UNIT_SP,16);

        viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                int tabCount = slideTablaout.getTabCount();
                for (int i = 0; i < tabCount; i++) {
                    TextView title = slideTablaout.getTitleView(i);
                    if (i == position) {
                        title.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                        title.setTextSize(TypedValue.COMPLEX_UNIT_SP,20);
                    } else {
                        title.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                        title.setTextSize(TypedValue.COMPLEX_UNIT_SP,16);
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
}
